package zhengqc.stack;

import zhengqc.list.List;

public abstract class AbstractStack<E> implements Stack<E> {
    protected List<E> data;

    @Override /* 获取栈内元素数量 */
    public int getSize() {
        return data.getSize();
    }
    @Override /* 栈是否为空 */
    public boolean isEmpty() {
        return data.isEmpty();
    }
    @Override /* 入栈 */
    public void push(E element) {
        data.addLast(element);
    }
    @Override /* 出栈 */
    public E pop() {
        if (isEmpty()) {
            throw new IllegalArgumentException("The Stack is empty!");
        }
        return data.removeLast();
    }
    @Override /* 查看栈顶元素 */
    public E peek() {
        if (isEmpty()) {
            throw new IllegalArgumentException("The Stack is empty!");
        }
        return data.getLast();
    }
    @Override /* 清空栈 */
    public void clear() {
        data.clear();
    }
}
